//
//  MergeCollectionViewCell.m
//  NewProject
//
//  Created by admin on 2017/6/15.
//  Copyright © 2017年 李航飞. All rights reserved.
//

#import "MergeCollectionViewCell.h"
@interface MergeCollectionViewCell ()
@property(nonatomic, strong)UIImageView *goodImageView;
@property(nonatomic, strong)UIImageView *typeImageView;
@property(nonatomic, strong)UIImageView *detaiImageView;
@property(nonatomic, strong)UILabel *nameLabel;
@property(nonatomic, strong)UILabel *priceLabel;
@property(nonatomic, strong)UIButton *addButton;

@end
@implementation MergeCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        _goodImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_goodImageView];
        
        _typeImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_typeImageView];
        
        _detaiImageView = [[UIImageView alloc]init];
        [self.contentView addSubview:_detaiImageView];

        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = FONT(15);
        _nameLabel.textColor = RGB0X(0x333333);
        [self.contentView addSubview:_nameLabel];
        
        _priceLabel = [[UILabel alloc]init];
        _priceLabel.font = FONT(14);
        _priceLabel.textAlignment = NSTextAlignmentCenter;
        _priceLabel.textColor = RGB0X(0xFF7E00);
        [self.contentView addSubview:_priceLabel];
        
        _addButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addButton setImage:[UIImage imageNamed:@"加"] forState:UIControlStateNormal];
        [_addButton addTarget:self action:@selector(addButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:_addButton];

        [self createConstraint];
    }
    return self;
}

- (void)createConstraint{
    [_goodImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(0);
        make.top.equalTo(self.contentView.mas_top).offset(0);
        make.size.mas_equalTo(CGSizeMake(187/WIDTH_6_SCALE,174/WIDTH_6_SCALE));
    }];
    [_typeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(15/WIDTH_6_SCALE);
        make.top.equalTo(self.goodImageView.mas_bottom).offset(18/WIDTH_6_SCALE);
        make.size.mas_equalTo(CGSizeMake(25/WIDTH_6_SCALE,15/WIDTH_6_SCALE));
    }];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.typeImageView.mas_right).offset(6/WIDTH_6_SCALE);
        make.top.equalTo(self.goodImageView.mas_bottom).offset(18/WIDTH_6_SCALE);
    }];
    [_detaiImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(15/WIDTH_6_SCALE);
        make.top.equalTo(self.typeImageView.mas_bottom).offset(11/WIDTH_6_SCALE);
        make.size.mas_equalTo(CGSizeMake(38/WIDTH_6_SCALE,14/WIDTH_6_SCALE));
    }];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(15/WIDTH_6_SCALE);
        make.top.equalTo(self.detaiImageView.mas_bottom).offset(16/WIDTH_6_SCALE);
    }];
    [_addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-25/WIDTH_6_SCALE);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-7/WIDTH_6_SCALE);
        make.size.mas_equalTo(CGSizeMake(26/WIDTH_6_SCALE,26/WIDTH_6_SCALE));
    }];
}

- (void)setModel:(NSDictionary *)model{
    _goodImageView.image = [UIImage imageNamed: model[kImage]];
    _nameLabel.text = model[kTitle];
    if([model[kType] isEqualToString:@"0"]){
        _typeImageView.image = [UIImage imageNamed:@"精选"];
    }
    if([model[kDetail] isEqualToString:@"0"]){
        _detaiImageView.image = [UIImage imageNamed:@"买一送一"];
    }
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:SF(@"¥%@",model[kPrice])];
    
    [AttributedStr addAttribute:NSFontAttributeName
     
                          value:FONT(8)
     
                          range:NSMakeRange(0, 1)];

    _priceLabel.attributedText = AttributedStr;
}

- (void)addButtonClick:(id )sender{
    
}
@end
